package com.hz.user.interfaces.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.hz.base.beans.vo.CommonResult;
import com.hz.base.beans.vo.PageEntity;
import com.hz.base.beans.vo.QueryParams;
import com.hz.beans.code.HzOperateCode;
import com.hz.beans.code.HzResultCode;
import com.hz.beans.user.entity.PRole;
import com.hz.common.beans.constant.DemoResult;
import com.hz.interfaces.user.inf.IPRoleInterface;
import com.hz.user.service.inf.IPRoleService;

/**
 * IPRoleService
 * @author liul
 * @since [0.0.1]
 * @version [0.0.1,2018年07月24日]
 */
@Service("pRoleInterface")
public class PRoleInterface implements IPRoleInterface{
	
	@Autowired
	private IPRoleService pRoleService;
	

	@Override
	public CommonResult<PRole> queryPRole(Long id) {
		CommonResult<PRole> cr = new DemoResult<>();
		cr = pRoleService.selectByPrimaryKey(cr,id);
		cr.setOperate(HzOperateCode.QUERY_PROLE);
		return cr;
	}

	@Override
	public CommonResult<PRole> addPRole(PRole pRole) {
		CommonResult<PRole> cr = new DemoResult<>();
		cr.setOperate(HzOperateCode.ADD_PROLE);
		if(pRole.getParentId()==null||
				(pRole.getParentId()!=null&&pRole.getParentId().equals(""))){
			cr.setResult(HzResultCode.EMPTY_OR_NULL_PARENTID);
		}
		cr = pRoleService.insert(cr, pRole);
		return cr;
	}
	
	@Override
	public CommonResult<PageEntity> queryForPage(QueryParams<PRole> queryParams) {
		CommonResult<PageEntity> cr = new DemoResult<>();
		cr = pRoleService.queryForPage(cr, queryParams);
		cr.setOperate(HzOperateCode.QUERY_PROLE_PAGE);
		return cr;
	}

	@Override
	public CommonResult<List<PRole>> queryPRoleList(QueryParams<PRole> queryParams) {
		CommonResult<List<PRole>> cr = new DemoResult<>();
		cr = pRoleService.queryForList(cr, queryParams);
		cr.setOperate(HzOperateCode.QUERY_PROLE_LIST);
		return cr;
	}

	@Override
	public CommonResult<PRole> updatePRole(PRole pRole) {
		CommonResult<PRole> cr = new DemoResult<>();
		cr = pRoleService.updateByPrimaryKey(cr, pRole);
		cr.setOperate(HzOperateCode.UPDATE_PROLE);
		return cr;
	}

	@Override
	public CommonResult<Object> deletePRoleArray(Long[] ids) {
		CommonResult<Object> cr = new DemoResult<>();
		cr = pRoleService.deleteObjectArray(cr, ids);
		cr.setOperate(HzOperateCode.DELETE_PROLE);
		return cr;
	}

	@Override
	public CommonResult<PRole> insertSelective(PRole pRole) {
		CommonResult<PRole> cr = new DemoResult<>();
		cr = pRoleService.insertSelective(cr, pRole);
		cr.setOperate(HzOperateCode.INSERTSELECTIVE_PROLE);
		return cr;
	}

	@Override
	public CommonResult<Object> deleteByList(List<PRole> pRoleList) {
		CommonResult<Object> cr = new DemoResult<>();
		cr = pRoleService.deleteByList(cr, pRoleList);
		cr.setOperate(HzOperateCode.DELETELIST_PROLE);
		return cr;
	}

	@Override
	public CommonResult<List<PRole>> batchUpdate(List<PRole> pRoleList) {
		CommonResult<List<PRole>> cr = new DemoResult<>();
		cr = pRoleService.batchUpdate(cr, pRoleList);
		cr.setOperate(HzOperateCode.BATCHUPDATE_PROLE);
		return cr;
	}

	@Override
	public CommonResult<List<PRole>> batchSave(List<PRole> pRoleList) {
		CommonResult<List<PRole>> cr = new DemoResult<>();
		cr = pRoleService.batchSave(cr, pRoleList);
		cr.setOperate(HzOperateCode.BATCHSAVE_PROLE);
		return cr;
	}

}
